#ifndef EIPIO_MEM_H
#define EIPIO_MEM_H

#include <stdint.h>

// plc -> robot
#define EIP_DI_NUM 64
#define EIP_AI_INT_NUM 24
#define EIP_AI_FLOAT_NUM 24

// robot - >plc
#define EIP_DO_NUM 64
#define EIP_AO_INT_NUM 24
#define EIP_AO_FLOAT_NUM 24

#define EIP_JOINT_INT_NUM 6
#define EIP_JOINT_FLOAT_NUM 24
#define EIP_JOINT_UINT8_NUM 4

#define EIP_TCP_FLOAT_NUM 30

#define EIP_ROBOT_OUT_INT_NUM 2
#define EIP_ROBOT_OUT_UINT8_NUM 4

#define EIP_SAFETY_OUT_INT_NUM 2
#define EIP_SAFETY_OUT_UINT8_NUM 4

#define EIP_ADAPTER_NAME_NUM 32

// eip mode data
#define EIP_MODE_IN_UINT8_NUM 492
#define EIP_MODE_OUT_UINT8_NUM 492

enum EIPState
{
    EIPStateDisable = 0,
    EIPStateInvalidCfgFile = 1,
    EIPStateNICFailed = 2,
    EIPStateMasterDisConnect = 3,
    EIPStateMasterConnect = 4
};

// Ethernet/IP Data
typedef struct EIPData
{
    int16_t DI[EIP_DI_NUM];
    int32_t AI_INT[EIP_AI_INT_NUM];
    float AI_FLOAT[EIP_AI_FLOAT_NUM];

    int16_t DO[EIP_DO_NUM];
    int32_t AO_INT[EIP_AO_INT_NUM];
    float AO_FLOAT[EIP_AO_FLOAT_NUM];

    int32_t JOINT_INT[EIP_JOINT_INT_NUM];
    float JOINT_FLOAT[EIP_JOINT_FLOAT_NUM];
    uint8_t JOINT_UINT8[EIP_JOINT_UINT8_NUM];

    float TCP_FLOAT[EIP_TCP_FLOAT_NUM];

    int32_t ROBOT_OUT_INT[EIP_ROBOT_OUT_INT_NUM];
    uint8_t ROBOT_OUT_UINT8[EIP_ROBOT_OUT_UINT8_NUM];

    int32_t SAFETY_OUT_INT[EIP_SAFETY_OUT_INT_NUM];
    uint8_t SAFETY_OUT_UINT8[EIP_SAFETY_OUT_UINT8_NUM];
} __attribute__((packed)) EIPData;

typedef struct EIPModeData
{
    uint8_t EIP_IN[EIP_MODE_IN_UINT8_NUM];
    uint8_t EIP_OUT[EIP_MODE_OUT_UINT8_NUM];
} __attribute__((packed)) EIPModeData;

//该类型需要在32位和64位的进程中进行内存共享所以统一按照紧凑模式对齐数据
typedef struct EIPShm
{
    int state;
    char enable;
    char mode;
    char adapter_name[32];
    char led_active;
    char led_state;
    short di_num;
    short do_num;
    short ai_int_num;
    short ai_float_num;
    short ao_int_num;
    short ao_float_num;
    unsigned int cabinetID;
    EIPModeData eipModeData;
    EIPData eipData;
} __attribute__((packed)) EIPShm;

#endif /*EIPIO_MEM_H*/
